package org.huzhp.controller;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.security.Principal;
import java.util.Map;

@Controller
public class IndexController {


    @GetMapping("login")
    public String login(HttpServletRequest request, Map map) {
        map.put("error", request.getSession().getAttribute("error"));
        request.getSession().removeAttribute("error");
        return "login";
    }

    @GetMapping("/")
    public String success() {
        return "success";
    }

    @GetMapping("user/me")
    @ResponseBody
    public Object me(Principal principal) {
        return principal;
    }

}
